<?php
/**
 * CreateUser: zlh
 * CreateTime: 2022/4/11 11:38
 * Remark:该类主要功能为旧版的dingtalk审批
 */

namespace App\Http\Controllers\Approval;

use App\Consts\ResponseConsts\ResponseStatusConsts;
use App\Func\ResponseFunc;
use App\Http\Controllers\Controller;
use App\Http\Requests\Approval\SendDingTalkApprovalPost;
use App\Service\Approval\OldDingTalkApprovalService;
use App\Tools\DingTalk\DingTalkApprovalProcess;

class OldDingTalkApprovalController extends Controller
{

    private OldDingTalkApprovalService $oldDingTalkApproval;

    public function __construct()
    {
        $this->oldDingTalkApproval = new OldDingTalkApprovalService();
    }

    /**
     * 发起钉钉审批实例
     * @param SendDingTalkApprovalPost $request
     */
    public function sendDingTalkApproval(SendDingTalkApprovalPost $request): \Illuminate\Http\JsonResponse
    {

        $approvals = $request->post('approvers_v2');
        $tmpId = $request->post('ding_talk_approval_template_id');

        return ResponseFunc::returnJson(
            'ok',
            ['processId' =>  $this->oldDingTalkApproval->sendOldApprovalProcess($approvals,$tmpId)],
            '发起审批实例成功',
            ResponseStatusConsts::CREATED_201_RESPONSE_STATUS
        );
    }

    /**
     * 获取当前用户审核数量
     * @param $userId
     * @return \Illuminate\Http\JsonResponse
     */
    public function getUserApprovalToDoNumber($userId): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            [
                "toDoNumber" => $this->oldDingTalkApproval->getUserApprovalToDoNumber($userId)
            ],
            '获取审批数量成功',
            ResponseStatusConsts::CREATED_201_RESPONSE_STATUS
        );
    }

    /**
     * 获取审批实例
     * @param $processId
     * @return \Illuminate\Http\JsonResponse
     */
    public function getDingTalkApprovalInfo($processId): \Illuminate\Http\JsonResponse
    {
        return ResponseFunc::returnJson(
            'ok',
            [
                "toDoNumber" => $this->oldDingTalkApproval->getDingTalkApprovalInfo($processId)
            ],
            '获取审批详情成功',
            ResponseStatusConsts::CREATED_201_RESPONSE_STATUS
        );
    }

    public function getDingTalkApprovalRecode($processId){
        return $this->oldDingTalkApproval->getDingTalkApprovalRecode($processId);
    }



}